package com.hawthorn.admin.repository.provider;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.builder.annotation.ProviderMethodResolver;

import java.util.Map;

/**
 * <p>todo 日志管理</p>
 * @author: guohao | 2607728024@qq.com
–
 * @created: 2022/7/21 15:30
 * @version v1.0.1
 * @copyright: Copyright (c) 2022 guohao
 */
@Slf4j
public class SysLogSqlProvider implements ProviderMethodResolver
{
  /**
   * <p>todo 获取用户登录日志</p>
   * @return: java.lang.String
   * @author: guohao | 2607728024@qq.com
   * @date: 2022/7/4 15:29
   * @version: 1.0.1
   * Modification History:
   * Date Author Version Description
   * -----------------------------------------------------------
   * 2022/7/4 guohao v1.0.1 init
   */
  public String selectLogInOperateLog(String conditions, Page<Map<String, Object>> page)
  {
    StringBuffer sql = new StringBuffer();
    sql.append(" select\n ");
    sql.append(" 	user_account 	userAccount,\n ");
    sql.append(" 	user_name 	userName,\n ");
    sql.append(" 	dept_id 	deptId,\n ");
    sql.append(" 	login_division 	loginDivision,\n ");
    sql.append(" 	login_realip 	loginRealip,\n ");
    sql.append(" 	login_ip 	loginIp,\n ");
    sql.append(" 	login_time 	loginTime,\n ");
    sql.append(" 	login_status 	loginStatus,\n ");
    sql.append(" 	logout_time logoutTime,\n ");
    sql.append(" 	browser \n ");
    sql.append(" from\n ");
    sql.append(" 	sys_log_login \n ");
    sql.append(" where\n ");
    sql.append(conditions);
    sql.append(" and 	del_flag = 0\n ");
    sql.append("order by create_time desc \n");
    return sql.toString();
  }

  /**
   * <p>todo 获取用户操作日志SQL</p>
   * @param conditions
   * @param page
   * @return: java.lang.String
   * @author: guohao | 2607728024@qq.com
   * @date: 2022/7/7 15:50
   * @version: 1.0.1
   * Modification History:
   * Date Author Version Description
   * -----------------------------------------------------------
   * 2022/7/7 guohao v1.0.1 init
   */
  public String selectOperationLog(String conditions, Page<Map<String, Object>> page)
  {
    StringBuffer sql = new StringBuffer();
    sql.append(" select\n ");
    sql.append(" 	lo.id,\n ");
    sql.append(" 	u.account,\n ");
    sql.append(" 	lo.user_id userId,\n ");
    sql.append(" 	lo.user_name userName,\n ");
    sql.append(" 	lo.browser browser,\n ");
    sql.append(" 	lo.operate_ip operateIp,\n ");
    sql.append(" 	lo.operate_division operateDivision,\n ");
    sql.append(" 	lo.exec_method execMethod,\n ");
    sql.append(" 	lo.exec_time execTime,\n ");
    sql.append(" 	lo.memo memo,\n ");
    sql.append(" 	lo.exec_params execParams,\n ");
    sql.append(" 	lo.user_dept_id userDeptId,\n ");
    sql.append(" 	lo.operate_ip operateIp,\n ");
    sql.append(" 	lo.create_time createTime \n ");
    sql.append(" from\n ");
    sql.append(" 	sys_log_operation lo\n ");
    sql.append(" 	left join sys_user u on lo.user_id = u.id\n ");
    sql.append(" where\n ");
    sql.append(conditions);
    sql.append(" and 	lo.del_flag = 0\n ");
    sql.append("order by lo.create_time desc \n");
    return sql.toString();
  }

  /**
   * <p>todo 操作日志导出</p>
   * @param headFields
   * @param conditions
   * @return: java.lang.String
   * @author: guohao | 2607728024@qq.com
   * @date: 2022/7/12 9:39
   * @version: 1.0.1
   * Modification History:
   * Date Author Version Description
   * -----------------------------------------------------------
   * 2022/7/12 guohao v1.0.1 init
   */
  public String exportOperationLog(String headFields, String conditions)
  {
    StringBuffer sql = new StringBuffer();
    sql.append(" select\n ");
    sql.append(headFields);
    sql.append(" from\n ");
    sql.append(" 	sys_log_operation lo\n ");
    sql.append(" 	left join sys_user u on lo.user_id = u.id\n ");
    sql.append(" where\n ");
    sql.append(conditions);
    sql.append(" and 	lo.del_flag = 0\n ");
    sql.append("order by lo.create_time desc \n");
    return sql.toString();
  }

  /**
   * <p>todo 用户登录日志导出</p>
   * @param headFields
   * @param conditions
   * @return: java.lang.String
   * @author: guohao | 2607728024@qq.com
   * @date: 2022/7/12 9:46
   * @version: 1.0.1
   * Modification History:
   * Date Author Version Description
   * -----------------------------------------------------------
   * 2022/7/12 guohao v1.0.1 init
   */
  public String exportLogInOperateLog(String headFields, String conditions)
  {
    StringBuffer sql = new StringBuffer();
    sql.append(" select\n ");
    sql.append(headFields);
    sql.append(" from\n ");
    sql.append(" 	sys_log_login \n ");
    sql.append(" where\n ");
    sql.append(conditions);
    sql.append(" and 	del_flag = 0\n ");
    sql.append("order by create_time desc \n");
    return sql.toString();
  }
}
